<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function Person() { }

    console.log(Person.prototype)
    // 在原有的原型对象上添加新的属性
    Person.prototype.message = "Hello World"
    Person.prototype.info = { name: "哈哈哈", age: 30 }
    Person.prototype.running = function () { }
    Person.prototype.eating = function () { }

    console.log(Object.getOwnPropertyDescriptor(Person.prototype, "constructor"))
    console.log(Object.keys(Person.prototype)) // ['message', 'info', 'running', 'eating']

    // 直接赋值一个新的原型对象
    Person.prototype = {
      message: "Hello World",
      info: { name: "哈哈哈", age: 30 },
      running: function () { },
      eating: function () { },
      constructor: Person
    }
    console.log(Object.keys(Person.prototype)) // ['message', 'info', 'running', 'eating', 'constructor']

    Person.prototype = {
      message: "Hello World",
      info: { name: "哈哈哈", age: 30 },
      running: function () { },
      eating: function () { },
    }
    Object.defineProperty(Person.prototype, "constructor",
      { writable: true, enumerable: false, configurable: true, value: Person }
    )
    console.log(Object.keys(Person.prototype))// ['message', 'info', 'running', 'eating']

    // 新建实例对象
    var p1 = new Person()
    console.log(p1.message)

  </script>
</body>

</html>